home *** CD-ROM | disk | FTP | other *** search
/ CDUTIL 13 / CDUTIL #13 Julio 1995.iso / windows / acadcom / ads / sample / calstdf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-08  |  49.8 KB  |  2,082 lines

  1. /* Next available MSG number is    11 */
  2.  
  3. /*****************************************************************************
  4.       CALSTDF.C
  5.       (C) Copyright 1988-1994 by Autodesk, Inc.
  6.  
  7.       This program is copyrighted by Autodesk, Inc. and is  licensed
  8.       to you under the following conditions.  You may not distribute
  9.       or  publish the source code of this program in any form.   You
  10.       may  incorporate this code in object form in derivative  works
  11.       provided  such  derivative  works  are  (i.) are  designed and 
  12.       intended  to  work  solely  with  Autodesk, Inc. products, and 
  13.       (ii.)  contain  Autodesk's  copyright  notice  "(C)  Copyright  
  14.       1988-1993 by Autodesk, Inc."
  15.  
  16.       AUTODESK  PROVIDES THIS PROGRAM "AS IS" AND WITH  ALL  FAULTS.
  17.       AUTODESK  SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF  MER-
  18.       CHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK,  INC.
  19.       DOES  NOT  WARRANT THAT THE OPERATION OF THE PROGRAM  WILL  BE
  20.       UNINTERRUPTED OR ERROR FREE.
  21.  
  22.   Description: Standard calculator functions.
  23.  
  24. *****************************************************************************/
  25.  
  26.  
  27. /****************************************************************************/
  28. /*  INCLUDES                                                                */
  29. /****************************************************************************/
  30.  
  31. #define MODULE_ID CALSTDF_C_
  32.  
  33. #include "cal.h"
  34.  
  35. #include "xmf.h"
  36. #include "ads_ix.h"
  37.  
  38.  
  39. /****************************************************************************/
  40. /*  STATIC VARIABLES AND FUNCTIONS                                          */
  41. /****************************************************************************/
  42.  
  43. static int pick_end_end   _((ads_point p1, ads_point p2, char fcn_name[]));
  44. static void set_lastpoint _((ads_point p));
  45. static void cal_snap      _((char snap_mode[]));
  46.  
  47.  
  48. /****************************************************************************/
  49. /*.doc sets_lastpoint(internal)*/
  50. /*+
  51.   Sets the value of the LASTPOINT AutoCAD variable.
  52. -*/
  53. /****************************************************************************/
  54.  
  55.  
  56. static void
  57. /*FCN*/set_lastpoint(p)
  58.  
  59.   ads_point p;
  60. {
  61.     struct resbuf rb;
  62.  
  63.     rb.restype = RT3DPOINT;
  64.     CPY_PNT(rb.resval.rpoint, p);
  65.     ads_setvar(/*MSG0*/"LASTPOINT", &rb);
  66. } /*set_lastpoint*/
  67.  
  68.  
  69. /****************************************************************************/
  70. /*.doc cal_rXof_func(internal)*/
  71. /*+
  72.   Calculator 'rXof()' function.
  73. -*/
  74. /****************************************************************************/
  75.  
  76.  
  77. static void
  78. /*FCN*/cal_rXof_func()
  79. {
  80.     if (no_of_params != 1) {
  81.         error(4, /*MSG0*/"rXof");
  82.         return;
  83.     }
  84.     if (!IS_VECTOR(0)) {
  85.         error(11, /*MSG0*/"rXof");
  86.         return;
  87.     }
  88.  
  89.     result.type = real_type;
  90.     result.r    = params[0].v[X];
  91. } /*cal_rXof_func*/
  92.  
  93.  
  94. /****************************************************************************/
  95. /*.doc cal_rYof_func(internal)*/
  96. /*+
  97.   Calculator 'rYof()' function.
  98. -*/
  99. /****************************************************************************/
  100.  
  101.  
  102. static void
  103. /*FCN*/cal_rYof_func()
  104. {
  105.     if (no_of_params != 1) {
  106.         error(4, /*MSG0*/"rYof");
  107.         return;
  108.     }
  109.     if (!IS_VECTOR(0)) {
  110.         error(11, /*MSG0*/"rYof");
  111.         return;
  112.     }
  113.  
  114.     result.type = real_type;
  115.     result.r    = params[0].v[Y];
  116. } /*cal_rYof_func*/
  117.  
  118.  
  119. /****************************************************************************/
  120. /*.doc cal_rZof_func(internal)*/
  121. /*+
  122.   Calculator 'rZof()' function.
  123. -*/
  124. /****************************************************************************/
  125.  
  126.  
  127. static void
  128. /*FCN*/cal_rZof_func()
  129. {
  130.     if (no_of_params != 1) {
  131.         error(4, /*MSG0*/"rZof");
  132.         return;
  133.     }
  134.     if (!IS_VECTOR(0)) {
  135.         error(11, /*MSG0*/"rZof");
  136.         return;
  137.     }
  138.  
  139.     result.type = real_type;
  140.     result.r    = params[0].v[Z];
  141. } /*cal_rZof_func*/
  142.  
  143.  
  144. /****************************************************************************/
  145. /*.doc cal_Xof_func(internal)*/
  146. /*+
  147.   Calculator 'Xof()' function.
  148. -*/
  149. /****************************************************************************/
  150.  
  151.  
  152. static void
  153. /*FCN*/cal_Xof_func()
  154. {
  155.     if (no_of_params != 1) {
  156.         error(4, /*MSG0*/"Xof");
  157.         return;
  158.     }
  159.  
  160.     result.type = vector_type;
  161.     result.v[X] = result.v[Y] = result.v[Z] = 0.0;
  162.  
  163.     if (params[0].type == vector_type) {
  164.         result.v[X] = params[0].v[X];
  165.     } else {
  166.         result.v[X] = params[0].r;
  167.     }
  168. } /*cal_Xof_func*/
  169.  
  170.  
  171. /****************************************************************************/
  172. /*.doc cal_Yof_func(internal)*/
  173. /*+
  174.   Calculator 'Yof()' function.
  175. -*/
  176. /****************************************************************************/
  177.  
  178.  
  179. static void
  180. /*FCN*/cal_Yof_func()
  181. {
  182.     if (no_of_params != 1) {
  183.         error(4, /*MSG0*/"Yof");
  184.         return;
  185.     }
  186.  
  187.     result.type = vector_type;
  188.     result.v[X] = result.v[Y] = result.v[Z] = 0.0;
  189.  
  190.     if (params[0].type == vector_type) {
  191.         result.v[Y] = params[0].v[Y];
  192.     } else {
  193.         result.v[Y] = params[0].r;
  194.     }
  195. } /*cal_Yof_func*/
  196.  
  197.  
  198. /****************************************************************************/
  199. /*.doc cal_Zof_func(internal)*/
  200. /*+
  201.   Calculator 'Zof()' function.
  202. -*/
  203. /****************************************************************************/
  204.  
  205.  
  206. static void
  207. /*FCN*/cal_Zof_func()
  208. {
  209.     if (no_of_params != 1) {
  210.         error(4, /*MSG0*/"Zof");
  211.         return;
  212.     }
  213.  
  214.     result.type = vector_type;
  215.     result.v[X] = result.v[Y] = result.v[Z] = 0.0;
  216.  
  217.     if (params[0].type == vector_type) {
  218.         result.v[Z] = params[0].v[Z];
  219.     } else {
  220.         result.v[Z] = params[0].r;
  221.     }
  222. } /*cal_Zof_func*/
  223.  
  224.  
  225. /****************************************************************************/
  226. /*.doc cal_XYof_func(internal)*/
  227. /*+
  228.   Calculator 'XYof()' function.
  229. -*/
  230. /****************************************************************************/
  231.  
  232.  
  233. static void
  234. /*FCN*/cal_XYof_func()
  235. {
  236.     if (no_of_params != 1) {
  237.         error(4, /*MSG0*/"XYof");
  238.         return;
  239.     }
  240.     if (!IS_VECTOR(0)) {
  241.         error(11, /*MSG0*/"XYof");
  242.         return;
  243.     }
  244.  
  245.     result = params[0];
  246.     result.v[Z] = 0.0;
  247. } /*cal_XYof_func*/
  248.  
  249.  
  250. /****************************************************************************/
  251. /*.doc cal_YZof_func(internal)*/
  252. /*+
  253.   Calculator 'YZof()' function.
  254. -*/
  255. /****************************************************************************/
  256.  
  257.  
  258. static void
  259. /*FCN*/cal_YZof_func()
  260. {
  261.     if (no_of_params != 1) {
  262.         error(4, /*MSG0*/"YZof");
  263.         return;
  264.     }
  265.     if (!IS_VECTOR(0)) {
  266.         error(11, /*MSG0*/"YZof");
  267.         return;
  268.     }
  269.  
  270.     result = params[0];
  271.     result.v[X] = 0.0;
  272. } /*cal_YZof_func*/
  273.  
  274.  
  275. /****************************************************************************/
  276. /*.doc cal_XZof_func(internal)*/
  277. /*+
  278.   Calculator 'XZof()' function.
  279. -*/
  280. /****************************************************************************/
  281.  
  282.  
  283. static void
  284. /*FCN*/cal_XZof_func()
  285. {
  286.     if (no_of_params != 1) {
  287.         error(4, /*MSG0*/"XZof");
  288.         return;
  289.     }
  290.     if (!IS_VECTOR(0)) {
  291.         error(11, /*MSG0*/"XZof");
  292.         return;
  293.     }
  294.  
  295.     result = params[0];
  296.     result.v[Y] = 0.0;
  297. } /*cal_XZof_func*/
  298.  
  299.  
  300. /****************************************************************************/
  301. /*.doc cal_ABS_func(internal)*/
  302. /*+
  303.   Calculator 'ABS()' function.
  304. -*/
  305. /****************************************************************************/
  306.  
  307.  
  308. static void
  309. /*FCN*/cal_ABS_func()
  310. {
  311.     if (no_of_params != 1) {
  312.         error(4, /*MSG0*/"ABS");
  313.         return;
  314.     }
  315.  
  316.     result.type = real_type;
  317.     if (params[0].type == vector_type) {
  318.         result.r = LENGTH(params[0].v);
  319.     } else {
  320.         result.r = fabs(params[0].r);
  321.     }
  322. } /*cal_ABS_func*/
  323.  
  324.  
  325. /****************************************************************************/
  326. /*.doc cal_ASIN_func(internal)*/
  327. /*+
  328.   Calculator 'ASIN()' function.
  329. -*/
  330. /****************************************************************************/
  331.  
  332.  
  333. static void
  334. /*FCN*/cal_ASIN_func()
  335. {
  336.     double a;
  337.  
  338.     if (no_of_params != 1) {
  339.         error(4, /*MSG0*/"ASIN");
  340.         return;
  341.     }
  342.     if (!IS_REAL(0)) {
  343.         error(12, /*MSG0*/"ASIN");
  344.         return;
  345.     }
  346.  
  347.     a = params[0].r;
  348.     result.type = real_type;
  349.  
  350.     if (fabs(a) > 1.1) {
  351.         error(13, /*MSG0*/"ASIN");
  352.         return;
  353.     }
  354.  
  355.     if (a >  1.0) {
  356.         a =  1.0;
  357.     } else if (a < -1.0) {
  358.         a = -1.0;
  359.     }
  360.  
  361.     result.r = asin(a) / DEGRAD;
  362. } /*cal_ASIN_func*/
  363.  
  364.  
  365. /****************************************************************************/
  366. /*.doc cal_ACOS_func(internal)*/
  367. /*+
  368.   Calculator 'ACOS()' function.
  369. -*/
  370. /****************************************************************************/
  371.  
  372.  
  373. static void
  374. /*FCN*/cal_ACOS_func()
  375. {
  376.     double a;
  377.  
  378.     if (no_of_params != 1) {
  379.         error(4, /*MSG0*/"ACOS");
  380.         return;
  381.     }
  382.     if (!IS_REAL(0)) {
  383.         error(12, /*MSG0*/"ACOS");
  384.         return;
  385.     }
  386.  
  387.     a = params[0].r;
  388.     result.type = real_type;
  389.  
  390.     if (fabs(a) > 1.1) {
  391.         error(13, /*MSG0*/"ACOS");
  392.         return;
  393.     }
  394.  
  395.     if (a >  1.0) {
  396.         a =  1.0;
  397.     } else if (a < -1.0) {
  398.         a = -1.0;
  399.     }
  400.  
  401.     result.r = acos(a) / DEGRAD;
  402. } /*cal_ACOS_func*/
  403.  
  404.  
  405. /****************************************************************************/
  406. /*.doc cal_ATAN_func(internal)*/
  407. /*+
  408.   Calculator 'ATAN()' function.
  409. -*/
  410. /****************************************************************************/
  411.  
  412.  
  413. static void
  414. /*FCN*/cal_ATAN_func()
  415. {
  416.     if (no_of_params != 1) {
  417.         error(4, /*MSG0*/"ATAN");
  418.         return;
  419.     }
  420.     if (!IS_REAL(0)) {
  421.         error(12, /*MSG0*/"ATAN");
  422.         return;
  423.     }
  424.  
  425.     result.type = real_type;
  426.     result.r    = atan(params[0].r) / DEGRAD;
  427. } /*cal_ATAN_func*/
  428.  
  429.  
  430. /****************************************************************************/
  431. /*.doc cal_SIN_func(internal)*/
  432. /*+
  433.   Calculator 'SIN()' function.
  434. -*/
  435. /****************************************************************************/
  436.  
  437.  
  438. static void
  439. /*FCN*/cal_SIN_func()
  440. {
  441.     if (no_of_params != 1) {
  442.         error(4, /*MSG0*/"SIN");
  443.         return;
  444.     }
  445.     if (!IS_REAL(0)) {
  446.         error(12, /*MSG0*/"SIN");
  447.         return;
  448.     }
  449.  
  450.     result.type = real_type;
  451.     result.r    = sin(DEGRAD * params[0].r);
  452. } /*cal_SIN_func*/
  453.  
  454.  
  455. /****************************************************************************/
  456. /*.doc cal_COS_func(internal)*/
  457. /*+
  458.   Calculator 'COS()' function.
  459. -*/
  460. /****************************************************************************/
  461.  
  462.  
  463. static void
  464. /*FCN*/cal_COS_func()
  465. {
  466.     if (no_of_params != 1) {
  467.         error(4, /*MSG0*/"COS");
  468.         return;
  469.     }
  470.     if (!IS_REAL(0)) {
  471.         error(12, /*MSG0*/"COS");
  472.         return;
  473.     }
  474.  
  475.     result.type = real_type;
  476.     result.r    = cos(DEGRAD * params[0].r);
  477. } /*cal_COS_func*/
  478.  
  479.  
  480. /****************************************************************************/
  481. /*.doc cal_TANG_func(internal)*/
  482. /*+
  483.   Calculator 'TANG()' function.
  484. -*/
  485. /****************************************************************************/
  486.  
  487.  
  488. static void
  489. /*FCN*/cal_TANG_func()
  490. {
  491.     if (no_of_params != 1) {
  492.         error(4, /*MSG0*/"TANG");
  493.         return;
  494.     }
  495.     if (!IS_REAL(0)) {
  496.         error(12, /*MSG0*/"TANG");
  497.         return;
  498.     }
  499.     if (fabs(fmod(fabs(params[0].r), 180.0) - 90.0) < EPS) {
  500.         error(24, NULL);
  501.         return;
  502.     }
  503.  
  504.     result.type = real_type;
  505.     result.r    = tan(DEGRAD * params[0].r);
  506. } /*cal_TANG_func*/
  507.  
  508.  
  509. /****************************************************************************/
  510. /*.doc cal_ROUND_func(internal)*/
  511. /*+
  512.   Calculator 'ROUND()' function.
  513. -*/
  514. /****************************************************************************/
  515.  
  516.  
  517. static void
  518. /*FCN*/cal_ROUND_func()
  519. {
  520.     double r;
  521.  
  522.     if (no_of_params != 1) {
  523.         error(4, /*MSG0*/"ROUND");
  524.         return;
  525.     }
  526.     if (!IS_REAL(0)) {
  527.         error(12, /*MSG0*/"ROUND");
  528.         return;
  529.     }
  530.  
  531.     r = floor(params[0].r + 0.5);
  532.  
  533.     if ((r > 32767) || (r < -32768)) {
  534.         error(14, NULL);
  535.         return;
  536.     }
  537.  
  538.     result.type = int_type;
  539.     result.r    = r;
  540. } /*cal_ROUND_func*/
  541.  
  542.  
  543. /****************************************************************************/
  544. /*.doc cal_TRUNC_func(internal)*/
  545. /*+
  546.   Calculator 'TRUNC()' function.
  547. -*/
  548. /****************************************************************************/
  549.  
  550.  
  551. static void
  552. /*FCN*/cal_TRUNC_func()
  553. {
  554.     double r;
  555.  
  556.     if (no_of_params != 1) {
  557.         error(4, /*MSG0*/"TRUNC");
  558.         return;
  559.     }
  560.     if (!IS_REAL(0)) {
  561.         error(12, /*MSG0*/"TRUNC");
  562.         return;
  563.     }
  564.  
  565.     r = params[0].r;
  566.  
  567.     if ((r > 32767) || (r < -32768)) {
  568.         error(14, NULL);
  569.         return;
  570.     }
  571.  
  572.     result.type = int_type;
  573.     result.r    = (int)(r);
  574. } /*cal_TRUNC_func*/
  575.  
  576.  
  577. /****************************************************************************/
  578. /*.doc cal_SQR_func(internal)*/
  579. /*+
  580.   Calculator 'SQR()' function.
  581. -*/
  582. /****************************************************************************/
  583.  
  584.  
  585. static void
  586. /*FCN*/cal_SQR_func()
  587. {
  588.     if (no_of_params != 1) {
  589.         error(4, /*MSG0*/"SQR");
  590.         return;
  591.     }
  592.     if (!IS_REAL(0)) {
  593.         error(12, /*MSG0*/"SQR");
  594.         return;
  595.     }
  596.  
  597.     result.type = real_type;
  598.     result.r    = SQR(params[0].r);
  599. } /*cal_SQR_func*/
  600.  
  601.  
  602. /****************************************************************************/
  603. /*.doc cal_SQRT_func(internal)*/
  604. /*+
  605.   Calculator 'SQRT()' function.
  606. -*/
  607. /****************************************************************************/
  608.  
  609.  
  610. static void
  611. /*FCN*/cal_SQRT_func()
  612. {
  613.     double r;
  614.  
  615.     if (no_of_params != 1) {
  616.         error(4, /*MSG0*/"SQRT");
  617.         return;
  618.     }
  619.     if (!IS_REAL(0)) {
  620.         error(12, /*MSG0*/"SQRT");
  621.         return;
  622.     }
  623.  
  624.     r = params[0].r;
  625.  
  626.     if (r < -EPS) {
  627.         error(15, NULL);
  628.         return;
  629.     }
  630.     if (r < 0.0) {
  631.         r = 0.0;
  632.     }
  633.  
  634.     result.type = real_type;
  635.     result.r    = sqrt(r);
  636. } /*cal_SQRT_func*/
  637.  
  638.  
  639. /****************************************************************************/
  640. /*.doc cal_R2Dfunc(internal)*/
  641. /*+
  642.   Calculator 'R2D()' function.
  643. -*/
  644. /****************************************************************************/
  645.  
  646.  
  647. static void
  648. /*FCN*/cal_R2D_func()
  649. {
  650.     if (no_of_params != 1) {
  651.         error(4, /*MSG0*/"R2D");
  652.         return;
  653.     }
  654.     if (!IS_REAL(0)) {
  655.         error(12, /*MSG0*/"R2D");
  656.         return;
  657.     }
  658.  
  659.     result.type = real_type;
  660.     result.r    = params[0].r / DEGRAD;
  661. } /*cal_R2D_func*/
  662.  
  663.  
  664. /****************************************************************************/
  665. /*.doc cal_D2R_func(internal)*/
  666. /*+
  667.   Calculator 'D2R()' function.
  668. -*/
  669. /****************************************************************************/
  670.  
  671.  
  672. static void
  673. /*FCN*/cal_D2R_func()
  674. {
  675.     if (no_of_params != 1) {
  676.         error(4, /*MSG0*/"D2R");
  677.         return;
  678.     }
  679.     if (!IS_REAL(0)) {
  680.         error(12, /*MSG0*/"D2R");
  681.         return;
  682.     }
  683.  
  684.     result.type = real_type;
  685.     result.r    = params[0].r * DEGRAD;
  686. } /*cal_D2R_func*/
  687.  
  688.  
  689. /****************************************************************************/
  690. /*.doc cal_LN_func(internal)*/
  691. /*+
  692.   Calculator 'LN()' function.
  693. -*/
  694. /****************************************************************************/
  695.  
  696.  
  697. static void
  698. /*FCN*/cal_LN_func()
  699. {
  700.     if (no_of_params != 1) {
  701.         error(4, /*MSG0*/"LN");
  702.         return;
  703.     }
  704.     if (!IS_REAL(0)) {
  705.         error(12, /*MSG0*/"LN");
  706.         return;
  707.     }
  708.     if (params[0].r <= 0.0) {
  709.         error(38, /*MSG0*/"LN");
  710.         return;
  711.     }
  712.     
  713.     result.type = real_type;
  714.     result.r    = log(params[0].r);
  715. } /*cal_LN_func*/
  716.  
  717.  
  718. /****************************************************************************/
  719. /*.doc cal_LOG_func(internal)*/
  720. /*+
  721.   Calculator 'LOG()' function.
  722. -*/
  723. /****************************************************************************/
  724.  
  725.  
  726. static void
  727. /*FCN*/cal_LOG_func()
  728. {
  729.     if (no_of_params != 1) {
  730.         error(4, /*MSG0*/"LOG");
  731.         return;
  732.     }
  733.     if (!IS_REAL(0)) {
  734.         error(12, /*MSG0*/"LOG");
  735.         return;
  736.     }
  737.     if (params[0].r <= 0.0) {
  738.         error(38, /*MSG0*/"LOG");
  739.         return;
  740.     }
  741.  
  742.     result.type = real_type;
  743.     result.r    = log10(params[0].r);
  744. } /*cal_LOG_func*/
  745.  
  746.  
  747. /****************************************************************************/
  748. /*.doc cal_EXP_func(internal)*/
  749. /*+
  750.   Calculator 'EXP()' function.
  751. -*/
  752. /****************************************************************************/
  753.  
  754.  
  755. static void
  756. /*FCN*/cal_EXP_func()
  757. {
  758.     if (no_of_params != 1) {
  759.         error(4, /*MSG0*/"EXP");
  760.         return;
  761.     }
  762.     if (!IS_REAL(0)) {
  763.         error(12, /*MSG0*/"EXP");
  764.         return;
  765.     }
  766.  
  767.     result.type = real_type;
  768.     result.r    = exp(params[0].r);
  769. } /*cal_EXP_func*/
  770.  
  771.  
  772. /****************************************************************************/
  773. /*.doc cal_EXP10_func(internal)*/
  774. /*+
  775.   Calculator 'EXP10()' function.
  776. -*/
  777. /****************************************************************************/
  778.  
  779.  
  780. static void
  781. /*FCN*/cal_EXP10_func()
  782. {
  783.     if (no_of_params != 1) {
  784.         error(4, /*MSG0*/"EXP10");
  785.         return;
  786.     }
  787.     if (!IS_REAL(0)) {
  788.         error(12, /*MSG0*/"EXP10");
  789.         return;
  790.     }
  791.  
  792.     result.type = real_type;
  793.     result.r    = exp(log(10.0) * params[0].r);
  794. } /*cal_EXP10_func*/
  795.  
  796.  
  797. /****************************************************************************/
  798. /*.doc cal_U2W_func(internal)*/
  799. /*+
  800.   Calculator 'U2W()' function.
  801. -*/
  802. /****************************************************************************/
  803.  
  804.  
  805. static void
  806. /*FCN*/cal_U2W_func()
  807. {
  808.     if (no_of_params != 1) {
  809.         error(4, /*MSG0*/"U2W");
  810.         return;
  811.     }
  812.     if (!IS_VECTOR(0)) {
  813.         error(11, /*MSG0*/"U2W");
  814.         return;
  815.     }
  816.  
  817.     result.type = vector_type;
  818.     sa_u2w(params[0].v, result.v);
  819. } /*cal_U2W_func*/
  820.  
  821.  
  822. /****************************************************************************/
  823. /*.doc cal_W2U_func(internal)*/
  824. /*+
  825.   Calculator 'W2U()' function.
  826. -*/
  827. /****************************************************************************/
  828.  
  829.  
  830. static void
  831. /*FCN*/cal_W2U_func()
  832. {
  833.     if (no_of_params != 1) {
  834.         error(4, /*MSG0*/"W2U");
  835.         return;
  836.     }
  837.     if (!IS_VECTOR(0)) {
  838.         error(11, /*MSG0*/"W2U");
  839.         return;
  840.     }
  841.  
  842.     result.type = vector_type;
  843.     sa_w2u(params[0].v, result.v);
  844. } /*cal_W2U_func*/
  845.  
  846.  
  847. /****************************************************************************/
  848. /*.doc cal_ANG_func(internal)*/
  849. /*+
  850.   Calculator 'ANG()' function.
  851. -*/
  852. /****************************************************************************/
  853.  
  854.  
  855. static void
  856. /*FCN*/cal_ANG_func()
  857. {
  858.     double    ang;
  859.     ads_point p0, p1, p2, p3, origin;
  860.     int       i, success;
  861.     int       all_vectors = TRUE;
  862.  
  863.     for (i = 0; i < no_of_params; i++) {
  864.         if (!IS_VECTOR(i)) {
  865.             all_vectors = FALSE;
  866.             break;
  867.         }
  868.     }
  869.  
  870.     if (!all_vectors || (no_of_params < 1) || (no_of_params > 4)) {
  871.         error(26, /*MSG0*/"ANG(v), ANG(p1,p2), ANG(apex,p1,p2), ANG(apex,p1,p2,p)");
  872.         return;
  873.     }
  874.  
  875.     CPY_PNT(p0, params[0].v);
  876.     CPY_PNT(p1, params[1].v);
  877.     CPY_PNT(p2, params[2].v);
  878.     CPY_PNT(p3, params[3].v);
  879.     origin[X] = origin[Y] = origin[Z] = 0.0;
  880.  
  881.     if (no_of_params == 1) {
  882.         p0[Z] = 0.0;
  883.         if (LENGTH(p0) < EPS) {
  884.             error(56, NULL);
  885.             return;
  886.         }
  887.         ang = ads_angle(origin, p0);
  888.  
  889.     } else if (no_of_params == 2) {
  890.         p0[Z] = p1[Z] = 0.0;
  891.         if (DISTANCE(p0, p1) < EPS) {
  892.             error(39, NULL);
  893.             return;
  894.         }
  895.         ang = ads_angle(p0, p1);
  896.  
  897.     } else if (no_of_params == 3) {
  898.         p0[Z] = p1[Z] = p2[Z] = 0.0;
  899.  
  900.         if ((DISTANCE(p0, p1) < EPS) ||
  901.             (DISTANCE(p0, p2) < EPS) ||
  902.             (DISTANCE(p1, p2) < EPS)) {
  903.             error(57, NULL);
  904.             return;
  905.         }
  906.         ang = ads_angle(p0, p2) - ads_angle(p0, p1);
  907.  
  908.     } else {                          /*no_of_params == 4*/
  909.  
  910.         ads_point normal, v1, v2;
  911.         double    d, dist;
  912.  
  913.         if ((DISTANCE(p0, p1) < EPS) || (DISTANCE(p0, p2) < EPS) ||
  914.             (DISTANCE(p0, p3) < EPS) || (DISTANCE(p1, p2) < EPS) ||
  915.             (DISTANCE(p1, p3) < EPS) || (DISTANCE(p2, p3) < EPS))  {
  916.             error(37, NULL);
  917.             return;
  918.         }
  919.  
  920.         success = sa_plane_equation(TRUE, p0, p1, p2, normal, &d);
  921.         if (success == RTNORM) {
  922.             dist = DOTPROD(normal, p3) + d;
  923.             if (fabs(dist) < EPS) {
  924.                 error(36, NULL);
  925.                 return;
  926.             }
  927.             if (dist > 0.0) {
  928.                 ADD_PNT(p3, p0, normal);
  929.             } else {
  930.                 SUB_PNT(p3, p0, normal);
  931.             }
  932.             ang = sa_angle_around_axis(p0, p3, p1, p2);
  933.         } else {
  934.             SUB_PNT(v1, p1, p0);
  935.             SUB_PNT(v2, p2, p0);
  936.             if (DOTPROD(v1, v2) > 0.0) {
  937.                 ang = 0.0;
  938.             } else {
  939.                 ang = PI;
  940.             }
  941.         }
  942.     }
  943.  
  944.     sa_normalize_angle(&ang);
  945.     result.type = real_type;
  946.     result.r    = ang / DEGRAD;
  947. } /*cal_ANG_func*/
  948.  
  949.  
  950. /****************************************************************************/
  951. /*.doc cal_RAD_func(internal)*/
  952. /*+
  953.   Calcualtor 'RAD' function.
  954. -*/
  955. /****************************************************************************/
  956.  
  957.  
  958. static void
  959. /*FCN*/cal_RAD_func()
  960. {
  961.     int    success;
  962.     double rad;
  963.  
  964.     if (no_of_params != 0) {
  965.         error(25, /*MSG0*/"RAD");
  966.         return;
  967.     }
  968.  
  969.     success = sa_get_radius_of_picked_entity(
  970. XMSG(">> Select circle, arc or polyline segment for RAD function:\n", 1),
  971.                                              &rad);
  972.     if (success != RTNORM) {
  973.         error(0, NULL);
  974.         return;
  975.     }
  976.  
  977.     result.type = real_type;
  978.     result.r    = rad;
  979. } /*cal_RAD_func*/
  980.  
  981.  
  982. /****************************************************************************/
  983. /*.doc cal_NOR_func(internal)*/
  984. /*+
  985.   Claculator 'NOR()' function.
  986. -*/
  987. /****************************************************************************/
  988.  
  989.  
  990. static void
  991. /*FCN*/cal_NOR_func()
  992. {
  993.     int        i, success;
  994.     ads_point  nor;
  995.     double     len;
  996.     int        all_vectors = TRUE;
  997.  
  998.     for (i = 0; i < no_of_params; i++) {
  999.         if (!IS_VECTOR(i)) {
  1000.             all_vectors = FALSE;
  1001.             break;
  1002.         }
  1003.     }
  1004.  
  1005.     if (!all_vectors || (no_of_params > 3)) {
  1006.         error(26, /*MSG0*/"NOR, NOR(v), NOR(p1,p2), NOR(p1,p2,p3)");
  1007.         return;
  1008.     }
  1009.  
  1010.     if (no_of_params == 0) {          /*3D normal to picked entity*/
  1011.         ads_point origin, xaxis, yaxis, zaxis;
  1012.  
  1013.         success = sa_get_cs_of_picked_entity(
  1014. XMSG(">> Select circle, arc or polyline for NOR function:\n", 2),
  1015. FALSE, origin,
  1016. xaxis, yaxis, zaxis);
  1017.         if (success != RTNORM) {
  1018.             error(0, NULL);
  1019.             return;
  1020.         }
  1021.  
  1022.         SUB_PNT(nor, zaxis, origin);
  1023.         sa_normalize(nor);
  1024.  
  1025.     } else if (no_of_params == 1) {   /*2D normal to vector*/
  1026.  
  1027.         nor[X] = -params[0].v[Y];
  1028.         nor[Y] =  params[0].v[X];
  1029.         nor[Z] = 0.0;
  1030.  
  1031.         len = LENGTH(nor);
  1032.         if (len < EPS) {
  1033.             error(30, NULL);
  1034.             return;
  1035.         }
  1036.  
  1037.         nor[X] /= len;
  1038.         nor[Y] /= len;
  1039.  
  1040.     } else if (no_of_params == 2) {   /*2D normal to line*/
  1041.  
  1042.         nor[X] = params[0].v[Y] - params[1].v[Y];
  1043.         nor[Y] = params[1].v[X] - params[0].v[X];
  1044.         nor[Z] = 0.0;
  1045.  
  1046.         len = LENGTH(nor);
  1047.         if (len < EPS) {
  1048.             error(61, /*MSG0*/"NOR(p1,p2)");
  1049.             return;
  1050.         }
  1051.  
  1052.         nor[X] /= len;
  1053.         nor[Y] /= len;
  1054.  
  1055.     } else {                          /*3D normal to plane by 3 points*/
  1056.         double d;
  1057.  
  1058.         if (!IS_VECTOR(0) || !IS_VECTOR(1) || !IS_VECTOR(2)) {
  1059.             error(26, /*MSG0*/"NOR, NOR(v), NOR(p1,p2), NOR(p1,p2,p3)");
  1060.             return;
  1061.         }
  1062.         success = sa_plane_equation(TRUE, params[0].v, params[1].v, 
  1063.                                     params[2].v,
  1064.                                     nor, &d);
  1065.         if (success != RTNORM) {
  1066.             error(51, NULL);
  1067.             return;
  1068.         }
  1069.     }
  1070.  
  1071.     result.type = vector_type;
  1072.     CPY_PNT(result.v, nor);
  1073. } /*cal_NOR_func*/
  1074.  
  1075.  
  1076. /****************************************************************************/
  1077. /*.doc cal_ILL_func(internal)*/
  1078. /*+
  1079.     Calculator 'ILL()' function.
  1080. -*/
  1081. /****************************************************************************/
  1082.  
  1083.  
  1084. static void
  1085. /*FCN*/cal_ILL_func()
  1086. {
  1087.     int success;
  1088.  
  1089.     if ((no_of_params != 4) ||
  1090.         !IS_VECTOR(0) || !IS_VECTOR(1) || !IS_VECTOR(2) || !IS_VECTOR(3)) {
  1091.         error(26, /*MSG0*/"ILL(p1,p2,p3,p4)");
  1092.         return;
  1093.     }
  1094.  
  1095.     if ((DISTANCE(params[0].v, params[1].v) < EPS) ||
  1096.         (DISTANCE(params[2].v, params[3].v) < EPS)) {
  1097.         error(40, /*MSG0*/"ILL");
  1098.         return;
  1099.     }
  1100.  
  1101.     result.type = vector_type;
  1102.     success = ads_inters(params[0].v, params[1].v,
  1103.                          params[2].v, params[3].v, 0, result.v);
  1104.  
  1105.     if (success != RTNORM) {
  1106.         error(54, /*MSG0*/"ILL");
  1107.         return;
  1108.     }
  1109. } /*cal_ILL_func*/
  1110.  
  1111.  
  1112. /****************************************************************************/
  1113. /*.doc cal_ILP_func(internal)*/
  1114. /*+
  1115.     Calculator 'ILP()' function.
  1116. -*/
  1117. /****************************************************************************/
  1118.  
  1119.  
  1120. static void
  1121. /*FCN*/cal_ILP_func()
  1122. {
  1123.     ads_point p, v, n;
  1124.     double    d, t, denom;
  1125.     int       success;
  1126.  
  1127.     if ((no_of_params != 5)            || 
  1128.         !IS_VECTOR(0) || !IS_VECTOR(1) || 
  1129.         !IS_VECTOR(2) || !IS_VECTOR(3) || !IS_VECTOR(4)) {
  1130.         
  1131.         error(26, /*MSG0*/"ILP(p1,p2,p3,p4,p5)");
  1132.         return;
  1133.     }
  1134.     
  1135.     CPY_PNT(p, params[0].v);
  1136.     SUB_PNT(v, params[1].v, params[0].v);
  1137.  
  1138.     if (LENGTH(v) < EPS) {
  1139.         error(40, /*MSG0*/"ILP");
  1140.         return;
  1141.     }
  1142.  
  1143.     success = sa_plane_equation(TRUE, params[2].v, params[3].v,
  1144.                                 params[4].v, 
  1145.                                 n, &d);
  1146.     if (success != RTNORM) {
  1147.         error(59, NULL);
  1148.         return;
  1149.     }
  1150.  
  1151.     denom = DOTPROD(n, v);
  1152.     if (fabs(denom) < EPS) {
  1153.         if (fabs(DOTPROD(p, n) + d) < EPS)
  1154.             error(62, NULL);
  1155.         else
  1156.             error(55, NULL);
  1157.         return;
  1158.     }
  1159.     t = -(d + DOTPROD(n, p)) / denom;
  1160.  
  1161.     result.type = vector_type;
  1162.     result.v[X] = p[X] + t * v[X];
  1163.     result.v[Y] = p[Y] + t * v[Y];
  1164.     result.v[Z] = p[Z] + t * v[Z];
  1165.  
  1166. } /*cal_ILP_func*/
  1167.  
  1168.  
  1169. /****************************************************************************/
  1170. /*.doc cal_DPL_func(internal)*/
  1171. /*+
  1172.     Calculator 'DPL()' function.
  1173. -*/
  1174. /****************************************************************************/
  1175.  
  1176.  
  1177. static void
  1178. /*FCN*/cal_DPL_func()
  1179. {
  1180.     ads_point q, p, v, qp, a;
  1181.     double    len, t;
  1182.  
  1183.     if ((no_of_params != 3) ||
  1184.         !IS_VECTOR(0) || !IS_VECTOR(1) || !IS_VECTOR(2)) {
  1185.         
  1186.         error(26, /*MSG0*/"DPL(p,p1,p2)");
  1187.         return;
  1188.     }
  1189.  
  1190.     CPY_PNT(q, params[0].v);
  1191.     CPY_PNT(p, params[1].v);
  1192.     SUB_PNT(v, params[2].v, params[1].v);
  1193.  
  1194.     len = LENGTH(v);
  1195.     if (len < EPS) {
  1196.         error(40, /*MSG0*/"DPL");
  1197.         return;
  1198.     }
  1199.  
  1200.     v[X] /= len;
  1201.     v[Y] /= len;
  1202.     v[Z] /= len;
  1203.  
  1204.     SUB_PNT(qp, q, p);
  1205.     t = DOTPROD(v, qp);
  1206.     a[X] = p[X] + t * v[X];
  1207.     a[Y] = p[Y] + t * v[Y];
  1208.     a[Z] = p[Z] + t * v[Z];
  1209.  
  1210.     result.type = real_type;
  1211.     result.r    = DISTANCE(q, a);
  1212.  
  1213. } /*cal_DPL_func*/
  1214.  
  1215.  
  1216. /****************************************************************************/
  1217. /*.doc cal_DPP_func(internal)*/
  1218. /*+
  1219.     Calculator 'DPP()' function.
  1220. -*/
  1221. /****************************************************************************/
  1222.  
  1223.  
  1224. static void
  1225. /*FCN*/cal_DPP_func()
  1226. {
  1227.     ads_point n;
  1228.     double    d;
  1229.     int       success;
  1230.  
  1231.     if ((no_of_params != 4) ||
  1232.         !IS_VECTOR(0) || !IS_VECTOR(1) || !IS_VECTOR(2) || !IS_VECTOR(3)) {
  1233.         
  1234.         error(26, /*MSG0*/"DPP(p,p1,p2,p3)");
  1235.         return;
  1236.     }
  1237.     
  1238.     success = sa_plane_equation(TRUE, params[1].v, params[2].v,
  1239.                                 params[3].v, 
  1240.                                 n,&d);
  1241.     if (success != RTNORM) {
  1242.         error(59, NULL);
  1243.         return;
  1244.     }
  1245.  
  1246.     result.type = real_type;
  1247.     result.r    = fabs(DOTPROD(n, params[0].v)+d);
  1248. } /*cal_DPP_func*/
  1249.  
  1250.  
  1251. /****************************************************************************/
  1252. /*.doc cal_PLT_func(internal)*/
  1253. /*+
  1254.     Calculator 'PLT()' function.
  1255. -*/
  1256. /****************************************************************************/
  1257.  
  1258.  
  1259. static void
  1260. /*FCN*/cal_PLT_func()
  1261. {
  1262.     double t1, t2;
  1263.  
  1264.     if ((no_of_params != 3) ||
  1265.         !IS_VECTOR(0) || !IS_VECTOR(1) || !IS_REAL(2)) {
  1266.         error(26, /*MSG0*/"PLT(p1,p2,t)");
  1267.         return;
  1268.     }
  1269.  
  1270.     t2 = params[2].r;
  1271.     t1 = 1.0 - t2;
  1272.  
  1273.     result.type = vector_type;
  1274.     result.v[X] = t1 * params[0].v[X] + t2 * params[1].v[X];
  1275.     result.v[Y] = t1 * params[0].v[Y] + t2 * params[1].v[Y];
  1276.     result.v[Z] = t1 * params[0].v[Z] + t2 * params[1].v[Z];
  1277.  
  1278. } /*cal_PLT_func*/
  1279.  
  1280.  
  1281. /****************************************************************************/
  1282. /*.doc cal_PLD_func(internal)*/
  1283. /*+
  1284.     Calculator 'PLD()' function.
  1285. -*/
  1286. /****************************************************************************/
  1287.  
  1288.  
  1289. static void
  1290. /*FCN*/cal_PLD_func()
  1291. {
  1292.     double d, d12, t1, t2;
  1293.  
  1294.     if ((no_of_params != 3) ||
  1295.         !IS_VECTOR(0) || !IS_VECTOR(1) || !IS_REAL(2)) {
  1296.         error(26, /*MSG0*/"PLD(p1,p2,dist)");
  1297.         return;
  1298.     }
  1299.  
  1300.     d = params[2].r;
  1301.     d12 = DISTANCE(params[0].v, params[1].v);
  1302.  
  1303.     if (d12 < EPS) {
  1304.         error(58, NULL);
  1305.         return;
  1306.     }
  1307.  
  1308.     t2 = d / d12;
  1309.     t1 = 1.0 - t2;
  1310.  
  1311.     result.type = vector_type;
  1312.     result.v[X] = t1 * params[0].v[X] + t2 * params[1].v[X];
  1313.     result.v[Y] = t1 * params[0].v[Y] + t2 * params[1].v[Y];
  1314.     result.v[Z] = t1 * params[0].v[Z] + t2 * params[1].v[Z];
  1315.  
  1316. } /*cal_PLD_func*/
  1317.  
  1318.  
  1319. /****************************************************************************/
  1320. /*.doc pick_end_end(internal) */
  1321. /*+
  1322.     Prompts the user to pick two entities by cursor and returns coordinates 
  1323.     of their endpoints in 'p1' and 'p2'.
  1324.  
  1325.     Function returns one of the standard ADS result codes.
  1326. -*/
  1327. /****************************************************************************/
  1328.  
  1329.  
  1330. static int
  1331. /*FCN*/pick_end_end(p1, p2, fcn_name)
  1332.  
  1333.   ads_point p1, p2;                   /* Returned endpoints */
  1334.   char      fcn_name[];               /* Prompt             */
  1335. {
  1336.     int  success;
  1337.     char prompt[128];
  1338.     int  ok = TRUE;
  1339.  
  1340.     do {
  1341.         strcpy(prompt, XMSG(">> Select one endpoint for ", 3));
  1342.         strcat(prompt, fcn_name);
  1343.         strcat(prompt, ":\n");
  1344.  
  1345.         success = sa_snap(prompt, /*MSG0*/"_END", p1);
  1346.         if (success != RTNORM)
  1347.             return(success);
  1348.  
  1349.         strcpy(prompt, XMSG(">> Select another endpoint for ", 4));
  1350.         strcat(prompt, fcn_name);
  1351.         strcat(prompt, ":\n");
  1352.  
  1353.         success = sa_snap(prompt, /*MSG0*/"_END", p2);
  1354.         if (success != RTNORM)
  1355.             return(success);
  1356.  
  1357.         if (DISTANCE(p1, p2) < EPS) {
  1358.             ads_printf(XMSG("\nThe two picked endpoints must be different.\n\n", 5));
  1359.             ok = FALSE;
  1360.         } else {
  1361.             ok = TRUE;
  1362.         }
  1363.     } while (!ok);
  1364.  
  1365.     return(RTNORM);
  1366. } /*pick_end_end*/
  1367.  
  1368.  
  1369. /****************************************************************************/
  1370. /*.doc cal_MEE_func(internal)*/
  1371. /*+
  1372.     Calculator 'MEE' function.
  1373. -*/
  1374. /****************************************************************************/
  1375.  
  1376.  
  1377. static void
  1378. /*FCN*/cal_MEE_func()
  1379. {
  1380.     ads_point p1, p2;
  1381.     int       success;
  1382.  
  1383.     if (no_of_params != 0) {
  1384.         error(25, /*MSG0*/"MEE");
  1385.         return;
  1386.     }
  1387.  
  1388.     success = pick_end_end(p1, p2, /*MSG0*/"MEE");
  1389.     if (success != RTNORM) {
  1390.         error(0, NULL);
  1391.         return;
  1392.     }
  1393.  
  1394.     result.type = vector_type;
  1395.     result.v[X] = (p1[X] + p2[X]) / 2;
  1396.     result.v[Y] = (p1[Y] + p2[Y]) / 2;
  1397.     result.v[Z] = (p1[Z] + p2[Z]) / 2;
  1398.  
  1399. } /*cal_MEE_func*/
  1400.  
  1401.  
  1402. /****************************************************************************/
  1403. /*.doc cal_DEE_func(internal)*/
  1404. /*+
  1405.     calculator 'DEE' function.
  1406. -*/
  1407. /****************************************************************************/
  1408.  
  1409.  
  1410. static void
  1411. /*FCN*/cal_DEE_func()
  1412. {
  1413.     ads_point p1, p2;
  1414.     int       success;
  1415.  
  1416.     if (no_of_params != 0) {
  1417.         error(25, /*MSG0*/"DEE");
  1418.         return;
  1419.     }
  1420.  
  1421.     success = pick_end_end(p1, p2, /*MSG0*/"DEE");
  1422.     if (success != RTNORM) {
  1423.         error(0, NULL);
  1424.         return;
  1425.     }
  1426.  
  1427.     result.type = real_type;
  1428.     result.r    = DISTANCE(p1, p2);
  1429.  
  1430. } /*cal_DEE_func*/
  1431.  
  1432.  
  1433. /****************************************************************************/
  1434. /*.doc cal_NEE_func(internal)*/
  1435. /*+
  1436.     Calculator 'NEE' function.
  1437. -*/
  1438. /****************************************************************************/
  1439.  
  1440.  
  1441. static void
  1442. /*FCN*/cal_NEE_func()
  1443. {
  1444.     ads_point p1, p2;
  1445.     ads_point n;
  1446.     double    len;
  1447.     int       success;
  1448.  
  1449.     if (no_of_params != 0) {
  1450.         error(25, /*MSG0*/"NEE");
  1451.         return;
  1452.     }
  1453.  
  1454.     success = pick_end_end(p1, p2, /*MSG0*/"NEE");
  1455.     if (success != RTNORM)  {
  1456.         error(61, /*MSG0*/"NEE");
  1457.         return;
  1458.     }
  1459.  
  1460.     n[X] = p1[Y] - p2[Y];
  1461.     n[Y] = p2[X] - p1[X];
  1462.     n[Z] = 0.0;
  1463.  
  1464.     len = LENGTH(n);
  1465.     if (len < EPS) {
  1466.         error(61, /*MSG0*/"NEE");
  1467.         return;
  1468.     }
  1469.  
  1470.     result.type = vector_type;
  1471.     result.v[X] = n[X] / len;
  1472.     result.v[Y] = n[Y] / len;
  1473.     result.v[Z] = 0.0;
  1474. } /*cal_NEE_func*/
  1475.  
  1476.  
  1477. /****************************************************************************/
  1478. /*.doc cal_VEE_func(internal)*/
  1479. /*+
  1480.     Calculator 'VEE' function.
  1481. -*/
  1482. /****************************************************************************/
  1483.  
  1484.  
  1485. static void
  1486. /*FCN*/cal_VEE_func()
  1487. {
  1488.     ads_point p1, p2;
  1489.     int       success;
  1490.  
  1491.     if (no_of_params != 0) {
  1492.         error(25, /*MSG0*/"VEE");
  1493.         return;
  1494.     }
  1495.  
  1496.     success = pick_end_end(p1, p2, /*MSG0*/"VEE");
  1497.     if (success != RTNORM) {
  1498.         error(0, NULL);
  1499.         return;
  1500.     }
  1501.  
  1502.     result.type = vector_type;
  1503.     SUB_PNT(result.v, p2, p1);
  1504. } /*cal_VEE_func*/
  1505.  
  1506.  
  1507. /****************************************************************************/
  1508. /*.doc cal_VEE1_func(internal)*/
  1509. /*+
  1510.     Calculator 'VEE1' function.
  1511. -*/
  1512. /****************************************************************************/
  1513.  
  1514.  
  1515. static void
  1516. /*FCN*/cal_VEE1_func()
  1517. {
  1518.     ads_point p1, p2;
  1519.     int       success;
  1520.  
  1521.     if (no_of_params != 0) {
  1522.         error(25, /*MSG0*/"VEE1");
  1523.         return;
  1524.     }
  1525.  
  1526.     success = pick_end_end(p1, p2, /*MSG0*/"VEE1");
  1527.     if (success != RTNORM) {
  1528.         error(0, NULL);
  1529.         return;
  1530.     }
  1531.  
  1532.     result.type = vector_type;
  1533.     SUB_PNT(result.v, p2, p1);
  1534.     sa_normalize(result.v);
  1535. } /*cal_VEE1_func*/
  1536.  
  1537.  
  1538. /****************************************************************************/
  1539. /*.doc cal_PLTEE_func(internal)*/
  1540. /*+
  1541.     Calculator 'PLTEE()' function.
  1542. -*/
  1543. /****************************************************************************/
  1544.  
  1545.  
  1546. static void
  1547. /*FCN*/cal_PLTEE_func()
  1548. {
  1549.     double    t1, t2;
  1550.     int       success;
  1551.     ads_point p1, p2;
  1552.  
  1553.     if ((no_of_params != 1) || !IS_REAL(0)) {
  1554.         error(26, /*MSG0*/"PLTEE(t)");
  1555.         return;
  1556.     }
  1557.  
  1558.     success = pick_end_end(p1, p2, /*MSG0*/"PLTEE");
  1559.     if (success != RTNORM) {
  1560.         error(0, NULL);
  1561.         return;
  1562.     }
  1563.  
  1564.     t2 = params[0].r;
  1565.     t1 = 1.0 - t2;
  1566.  
  1567.     result.type = vector_type;
  1568.     result.v[X] = t1 * p1[X] + t2 * p2[X];
  1569.     result.v[Y] = t1 * p1[Y] + t2 * p2[Y];
  1570.     result.v[Z] = t1 * p1[Z] + t2 * p2[Z];
  1571.  
  1572. } /*cal_PLTEE_func*/
  1573.  
  1574.  
  1575. /****************************************************************************/
  1576. /*.doc cal_PLDEE_func(internal)*/
  1577. /*+
  1578.     Calculator 'PLDEE()' function.
  1579. -*/
  1580. /****************************************************************************/
  1581.  
  1582.  
  1583. static void
  1584. /*FCN*/cal_PLDEE_func()
  1585. {
  1586.     double    d, d12, t1, t2;
  1587.     ads_point p1, p2;
  1588.     int       success;
  1589.  
  1590.     if ((no_of_params != 1) || !IS_REAL(0)) {
  1591.         error(26, /*MSG0*/"PLDEE(dist)");
  1592.         return;
  1593.     }
  1594.  
  1595.     success = pick_end_end(p1, p2, /*MSG0*/"PLDEE");
  1596.     if (success != RTNORM) {
  1597.         error(0, NULL);
  1598.         return;
  1599.     }
  1600.  
  1601.     d = params[0].r;
  1602.     d12 = DISTANCE(p1, p2);
  1603.  
  1604.     t2 = d / d12;
  1605.     t1 = 1.0 - t2;
  1606.  
  1607.     result.type = vector_type;
  1608.     result.v[X] = t1 * p1[X] + t2 * p2[X];
  1609.     result.v[Y] = t1 * p1[Y] + t2 * p2[Y];
  1610.     result.v[Z] = t1 * p1[Z] + t2 * p2[Z];
  1611.  
  1612. } /*cal_PLDEE_func*/
  1613.  
  1614.  
  1615. /****************************************************************************/
  1616. /*.doc cal_ILLE_func(internal)*/
  1617. /*+
  1618.     Calculator 'ILLE()' function.
  1619. -*/
  1620. /****************************************************************************/
  1621.  
  1622.  
  1623. static void
  1624. /*FCN*/cal_ILLE_func()
  1625. {
  1626.     int       success;
  1627.     ads_point p1, p2, p3, p4;
  1628.  
  1629.     if (no_of_params != 0) {
  1630.         error(25, /*MSG0*/"ILLE");
  1631.         return;
  1632.     }
  1633.  
  1634.     success = pick_end_end(p1, p2, XMSG("ILLE:First line", 6));
  1635.     if (success != RTNORM) {
  1636.         error(0, NULL);
  1637.         return;
  1638.     }
  1639.  
  1640.     success = pick_end_end(p3, p4, XMSG("ILLE:Second line", 7));
  1641.     if (success != RTNORM) {
  1642.         error(0, NULL);
  1643.         return;
  1644.     }
  1645.  
  1646.     result.type = vector_type;
  1647.     success = ads_inters(p1, p2, p3, p4, 0, result.v);
  1648.     if (success != RTNORM) {
  1649.         error(54, /*MSG0*/"ILLE");
  1650.         return;
  1651.     }
  1652.  
  1653. } /*cal_ILLE_func*/
  1654.  
  1655.  
  1656. /****************************************************************************/
  1657. /*.doc cal_DISP_func(internal)*/
  1658. /*+
  1659.     Calculator 'DIST()' function.
  1660. -*/
  1661. /****************************************************************************/
  1662.  
  1663.  
  1664. static void
  1665. /*FCN*/cal_DIST_func()
  1666. {
  1667.     if ((no_of_params != 2) || !IS_VECTOR(0) || !IS_VECTOR(1)) {
  1668.         error(26, /*MSG0*/"DIST(p1,p2)");
  1669.         return;
  1670.     }
  1671.  
  1672.     result.type = real_type;
  1673.     result.r    = DISTANCE(params[0].v, params[1].v);
  1674. } /*cal_DIST_func*/
  1675.  
  1676.  
  1677. /****************************************************************************/
  1678. /*.doc cal_VEC_func(internal)*/
  1679. /*+
  1680.     Calculator 'VEC()' function.
  1681. -*/
  1682. /****************************************************************************/
  1683.  
  1684.  
  1685. static void
  1686. /*FCN*/cal_VEC_func()
  1687. {
  1688.     if ((no_of_params != 2) || !IS_VECTOR(0) || !IS_VECTOR(1)) {
  1689.         error(26, /*MSG0*/"VEC(FromPt,ToPt)");
  1690.         return;
  1691.     }
  1692.  
  1693.     result.type = vector_type;
  1694.     SUB_PNT(result.v, params[1].v, params[0].v);
  1695. } /*cal_VEC_func*/
  1696.  
  1697.  
  1698. /****************************************************************************/
  1699. /*.doc cal_VEC1_func(internal)*/
  1700. /*+
  1701.     Calculator 'VEC1()' function.
  1702. -*/
  1703. /****************************************************************************/
  1704.  
  1705.  
  1706. static void
  1707. /*FCN*/cal_VEC1_func()
  1708. {
  1709.     if ((no_of_params != 2) || !IS_VECTOR(0) || !IS_VECTOR(1)) {
  1710.         error(26, /*MSG0*/"VEC1(FromPt,ToPt)");
  1711.         return;
  1712.     }
  1713.  
  1714.     result.type = vector_type;
  1715.     SUB_PNT(result.v, params[1].v, params[0].v);
  1716.     sa_normalize(result.v);
  1717. } /*cal_VEC1_func*/
  1718.  
  1719.  
  1720. /****************************************************************************/
  1721. /*.doc cal_ROT_func(internal)*/
  1722. /*+
  1723.     Calculator 'ROT()' function.
  1724. -*/
  1725. /****************************************************************************/
  1726.  
  1727.  
  1728. static void
  1729. /*FCN*/cal_ROT_func()
  1730. {
  1731.     ads_point p, p1, p2;
  1732.     double    angle;
  1733.     int       success, given_3_points, given_4_points;
  1734.  
  1735.     given_3_points = ((no_of_params == 3) &&
  1736.                       IS_VECTOR(0) && IS_VECTOR(1) && IS_REAL(2));
  1737.     given_4_points = ((no_of_params == 4) &&
  1738.                       IS_VECTOR(0) && IS_VECTOR(1) &&
  1739.                       IS_VECTOR(2) && IS_REAL(3));
  1740.  
  1741.     if (!given_3_points && !given_4_points) {
  1742.         error(26, /*MSG0*/"ROT(p,origin,angle) or ROT(p,p1ax,p2ax,angle)");
  1743.         return;
  1744.     }
  1745.  
  1746.     CPY_PNT(p,  params[0].v);
  1747.     CPY_PNT(p1, params[1].v);
  1748.  
  1749.     if (given_3_points) {
  1750.         CPY_PNT(p2, p1);
  1751.         p2[Z] += 1.0;
  1752.         angle = params[2].r;
  1753.     } else {
  1754.         CPY_PNT(p2, params[2].v);
  1755.         angle = params[3].r;
  1756.     }
  1757.  
  1758.     if (DISTANCE(p1, p2) < EPS) {
  1759.         error(53, NULL);
  1760.         return;
  1761.     }
  1762.  
  1763.     success = sa_rotate_point_around_axis(p, (angle * DEGRAD), p1, p2);
  1764.     if (success != RTNORM) {
  1765.         error(48, NULL);
  1766.         return;
  1767.     }
  1768.  
  1769.     result.type = vector_type;
  1770.     CPY_PNT(result.v, p);
  1771. } /*cal_ROT_func*/
  1772.  
  1773.  
  1774. /****************************************************************************/
  1775. /*.doc cal_CUR_func(internal)*/
  1776. /*+
  1777.     Calculator 'CUR' function.
  1778. -*/
  1779. /****************************************************************************/
  1780.  
  1781.  
  1782. static void
  1783. /*FCN*/cal_CUR_func()
  1784. {
  1785.     int success;
  1786.  
  1787.     if (no_of_params != 0) {
  1788.         error(25, /*MSG0*/"CUR");
  1789.         return;
  1790.     }
  1791.     
  1792.     result.type = vector_type;
  1793.     ads_initget(1+8, NULL);
  1794.     
  1795.     success = ads_getpoint(NULL, XMSG(">> Enter a point:\n", 8), result.v);
  1796.     
  1797.     if (success != RTNORM) {
  1798.         error(0, NULL);
  1799.         return;
  1800.     }
  1801.     set_lastpoint(result.v);
  1802. } /*cal_CUR_func*/
  1803.  
  1804.  
  1805. /****************************************************************************/
  1806. /*.doc cal_snap(internal)*/
  1807. /*+
  1808.    Local snap function.
  1809. -*/
  1810. /****************************************************************************/
  1811.  
  1812.  
  1813. static void
  1814. /*FCN*/cal_snap(snap_mode)
  1815.  
  1816.   char snap_mode[];                   /* String "END", "MID", "CEN", etc. */
  1817. {
  1818.     char prompt[128];
  1819.     int  success;
  1820.  
  1821.     if (no_of_params != 0) {
  1822.         error(25, snap_mode);
  1823.         return;
  1824.     }
  1825.  
  1826.     strcpy(prompt, XMSG(">> Select entity for ", 9));
  1827.  
  1828.     /* Skip the underscore prefix of the snap mode */
  1829.  
  1830.     if (snap_mode[0] != '_') {
  1831.         strcat(prompt, snap_mode);
  1832.     } else {
  1833.         strcat(prompt, snap_mode + 1);
  1834.     }
  1835.     strcat(prompt, XMSG(" snap:\n", 10));
  1836.  
  1837.     result.type = vector_type;
  1838.     success = sa_snap(prompt, snap_mode, result.v);
  1839.  
  1840.     if (success != RTNORM) {
  1841.         error(0, NULL);
  1842.     }
  1843.     set_lastpoint(result.v);
  1844. } /*cal_snap*/
  1845.  
  1846.  
  1847. /****************************************************************************/
  1848. /*.doc cal_END_func(internal)*/
  1849. /*+
  1850.     Calculator 'END' snap function.
  1851. -*/
  1852. /****************************************************************************/
  1853.  
  1854.  
  1855. static void
  1856. /*FCN*/cal_END_func()
  1857. {
  1858.     cal_snap(/*MSG0*/"_END");
  1859. } /*cal_END_func*/
  1860.  
  1861.  
  1862. /****************************************************************************/
  1863. /*.doc cal_MID_func(internal)*/
  1864. /*+
  1865.     Calculator 'MID' snap function.
  1866. -*/
  1867. /****************************************************************************/
  1868.  
  1869.  
  1870. static void
  1871. /*FCN*/cal_MID_func()
  1872. {
  1873.     cal_snap(/*MSG0*/"_MID");
  1874. } /*cal_MID_func*/
  1875.  
  1876.  
  1877. /****************************************************************************/
  1878. /*.doc cal_CEN_func(internal)*/
  1879. /*+
  1880.     Calculator 'CEN' snap function.
  1881. -*/
  1882. /****************************************************************************/
  1883.  
  1884.  
  1885. static void
  1886. /*FCN*/cal_CEN_func()
  1887. {
  1888.     cal_snap(/*MSG0*/"_CEN");
  1889. } /*cal_CEN_func*/
  1890.  
  1891.  
  1892. /****************************************************************************/
  1893. /*.doc cal_INT_func(internal)*/
  1894. /*+
  1895.     Calculator 'INT' snap function.
  1896. -*/
  1897. /****************************************************************************/
  1898.  
  1899.  
  1900. static void
  1901. /*FCN*/cal_INT_func()
  1902. {
  1903.     cal_snap(/*MSG0*/"_INT");
  1904. } /*cal_INT_func*/
  1905.  
  1906.  
  1907. /****************************************************************************/
  1908. /*.doc cal_NEA_func(internal)*/
  1909. /*+
  1910.     Calculator 'NEA' snap function.
  1911. -*/
  1912. /****************************************************************************/
  1913.  
  1914.  
  1915. static void
  1916. /*FCN*/cal_NEA_func()
  1917. {
  1918.     cal_snap(/*MSG0*/"_NEA");
  1919. } /*cal_NEA_func*/
  1920.  
  1921.  
  1922. /****************************************************************************/
  1923. /*.doc cal_NOD_func(internal)*/
  1924. /*+
  1925.     Calculator 'NOD' snap function.
  1926. -*/
  1927. /****************************************************************************/
  1928.  
  1929.  
  1930. static void
  1931. /*FCN*/cal_NOD_func()
  1932. {
  1933.     cal_snap(/*MSG0*/"_NOD");
  1934. } /*cal_NOD_func*/
  1935.  
  1936.  
  1937. /****************************************************************************/
  1938. /*.doc cal_QUA_func(internal)*/
  1939. /*+
  1940.     Calculator 'QUA' snap function.
  1941. -*/
  1942. /****************************************************************************/
  1943.  
  1944.  
  1945. static void
  1946. /*FCN*/cal_QUA_func()
  1947. {
  1948.     cal_snap(/*MSG0*/"_QUA");
  1949. } /*cal_QUA_func*/
  1950.  
  1951.  
  1952. /****************************************************************************/
  1953. /*.doc cal_PER_func(internal)*/
  1954. /*+
  1955.     Calculator 'PER' snap function.
  1956. -*/
  1957. /****************************************************************************/
  1958.  
  1959.  
  1960. static void
  1961. /*FCN*/cal_PER_func()
  1962. {
  1963.     cal_snap(/*MSG0*/"_PER");
  1964. } /*cal_PER_func*/
  1965.  
  1966.  
  1967. /****************************************************************************/
  1968. /*.doc cal_TAN_func(internal)*/
  1969. /*+
  1970.     Calculator 'TAN' snap function.
  1971. -*/
  1972. /****************************************************************************/
  1973.  
  1974.  
  1975. static void
  1976. /*FCN*/cal_TAN_func()
  1977. {
  1978.     cal_snap(/*MSG0*/"_TAN");
  1979. } /*cal_TAN_func*/
  1980.  
  1981.  
  1982. /****************************************************************************/
  1983. /*.doc cal_INS_func(internal)*/
  1984. /*+
  1985.     Calculator 'INS' snap function.
  1986. -*/
  1987. /****************************************************************************/
  1988.  
  1989.  
  1990. static void
  1991. /*FCN*/cal_INS_func()
  1992. {
  1993.     cal_snap(/*MSG0*/"_INS");
  1994. } /*cal_INS_func*/
  1995.  
  1996.  
  1997. /****************************************************************************/
  1998. /*.doc cal_register_standard_functions(external)*/
  1999. /*+
  2000.   Registers the standard calculator functions in this file. This function
  2001.   is called only once during the phase of loading the calculator.
  2002. -*/
  2003. /****************************************************************************/
  2004.  
  2005.  
  2006. void
  2007. /*FCN*/cal_register_standard_functions()
  2008. {
  2009.     cal_register_function(/*MSG0*/"END",     cal_END_func  );
  2010.     cal_register_function(/*MSG0*/"MID",     cal_MID_func  );
  2011.     cal_register_function(/*MSG0*/"CEN",     cal_CEN_func  );
  2012.     cal_register_function(/*MSG0*/"INT",     cal_INT_func  );
  2013.     cal_register_function(/*MSG0*/"NEA",     cal_NEA_func  );
  2014.     cal_register_function(/*MSG0*/"NOD",     cal_NOD_func  );
  2015.     cal_register_function(/*MSG0*/"QUA",     cal_QUA_func  );
  2016.     cal_register_function(/*MSG0*/"PER",     cal_PER_func  );
  2017.     cal_register_function(/*MSG0*/"TAN",     cal_TAN_func  );
  2018.     cal_register_function(/*MSG0*/"INS",     cal_INS_func  );
  2019.  
  2020.     cal_register_function(/*MSG0*/"ANG",     cal_ANG_func  );
  2021.     cal_register_function(/*MSG0*/"RAD",     cal_RAD_func  );
  2022.     cal_register_function(/*MSG0*/"NOR",     cal_NOR_func  );
  2023.  
  2024.     cal_register_function(/*MSG0*/"SIN",     cal_SIN_func  );
  2025.     cal_register_function(/*MSG0*/"COS",     cal_COS_func  );
  2026.     cal_register_function(/*MSG0*/"TANG",    cal_TANG_func );
  2027.     cal_register_function(/*MSG0*/"ASIN",    cal_ASIN_func );
  2028.     cal_register_function(/*MSG0*/"ACOS",    cal_ACOS_func );
  2029.     cal_register_function(/*MSG0*/"ATAN",    cal_ATAN_func );
  2030.  
  2031.     cal_register_function(/*MSG0*/"ABS",     cal_ABS_func  );
  2032.     cal_register_function(/*MSG0*/"LN",      cal_LN_func   );
  2033.     cal_register_function(/*MSG0*/"LOG",     cal_LOG_func  );
  2034.     cal_register_function(/*MSG0*/"EXP",     cal_EXP_func  );
  2035.     cal_register_function(/*MSG0*/"EXP10",   cal_EXP10_func);
  2036.     cal_register_function(/*MSG0*/"SQR",     cal_SQR_func  );
  2037.     cal_register_function(/*MSG0*/"SQRT",    cal_SQRT_func );
  2038.  
  2039.     cal_register_function(/*MSG0*/"XOF",     cal_Xof_func  );
  2040.     cal_register_function(/*MSG0*/"YOF",     cal_Yof_func  );
  2041.     cal_register_function(/*MSG0*/"ZOF",     cal_Zof_func  );
  2042.     cal_register_function(/*MSG0*/"RXOF",    cal_rXof_func );
  2043.     cal_register_function(/*MSG0*/"RYOF",    cal_rYof_func );
  2044.     cal_register_function(/*MSG0*/"RZOF",    cal_rZof_func );
  2045.     cal_register_function(/*MSG0*/"XYOF",    cal_XYof_func );
  2046.     cal_register_function(/*MSG0*/"YZOF",    cal_YZof_func );
  2047.     cal_register_function(/*MSG0*/"XZOF",    cal_XZof_func );
  2048.  
  2049.     cal_register_function(/*MSG0*/"R2D",     cal_R2D_func  );
  2050.     cal_register_function(/*MSG0*/"D2R",     cal_D2R_func  );
  2051.     cal_register_function(/*MSG0*/"ROUND",   cal_ROUND_func);
  2052.     cal_register_function(/*MSG0*/"TRUNC",   cal_TRUNC_func);
  2053.  
  2054.     cal_register_function(/*MSG0*/"U2W",     cal_U2W_func  );
  2055.     cal_register_function(/*MSG0*/"W2U",     cal_W2U_func  );
  2056.  
  2057.     cal_register_function(/*MSG0*/"ILL",     cal_ILL_func  );
  2058.     cal_register_function(/*MSG0*/"ILP",     cal_ILP_func  );
  2059.     cal_register_function(/*MSG0*/"DPL",     cal_DPL_func  );
  2060.     cal_register_function(/*MSG0*/"DPP",     cal_DPP_func  );
  2061.     cal_register_function(/*MSG0*/"PLT",     cal_PLT_func  );
  2062.     cal_register_function(/*MSG0*/"PLD",     cal_PLD_func  );
  2063.  
  2064.     cal_register_function(/*MSG0*/"MEE",     cal_MEE_func  );
  2065.     cal_register_function(/*MSG0*/"DEE",     cal_DEE_func  );
  2066.     cal_register_function(/*MSG0*/"NEE",     cal_NEE_func  );
  2067.     cal_register_function(/*MSG0*/"VEE",     cal_VEE_func  );
  2068.     cal_register_function(/*MSG0*/"VEE1",    cal_VEE1_func );
  2069.     cal_register_function(/*MSG0*/"PLTEE",   cal_PLTEE_func);
  2070.     cal_register_function(/*MSG0*/"PLDEE",   cal_PLDEE_func);
  2071.     cal_register_function(/*MSG0*/"ILLE",    cal_ILLE_func );
  2072.  
  2073.     cal_register_function(/*MSG0*/"DIST",    cal_DIST_func );
  2074.     cal_register_function(/*MSG0*/"VEC",     cal_VEC_func  );
  2075.     cal_register_function(/*MSG0*/"VEC1",    cal_VEC1_func );
  2076.     cal_register_function(/*MSG0*/"ROT",     cal_ROT_func  );
  2077.     cal_register_function(/*MSG0*/"CUR",     cal_CUR_func  );
  2078.  
  2079. } /*cal_register_standard_functions*/
  2080.  
  2081.  
  2082.